From 8af9e95d35fab9baa8779e686684a7d8c0192c33 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Fri, 10 Feb 2017 18:50:17 -0800 Subject: [PATCH] Increase copypastafication of `cargo search` Formats the search results printed by `cargo search` so that they can be copied directly into a `Cargo.toml` file. --- src/cargo/ops/registry.rs | 4 ++-- tests/search.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cargo/ops/registry.rs b/src/cargo/ops/registry.rs index 5d35b71e3..1a602a9d4 100644 --- a/src/cargo/ops/registry.rs +++ b/src/cargo/ops/registry.rs @@ -424,7 +424,7 @@ pub fn search(query: &str, let list_items = crates.iter() .map(|krate| ( - format!("{} ({})", krate.name, krate.max_version), + format!("{} = \"^{}\"", krate.name, krate.max_version), krate.description.as_ref().map(|desc| truncate_with_ellipsis(&desc.replace("\n", " "), 128)) )) @@ -439,7 +439,7 @@ pub fn search(query: &str, Some(desc) => { let space = repeat(' ').take(description_margin - name.len()) .collect::(); - name + &space + &desc + name + &space + "# " + &desc } None => name }; diff --git a/tests/search.rs b/tests/search.rs index b2f1c8ad1..4fd6678b0 100644 --- a/tests/search.rs +++ b/tests/search.rs @@ -87,7 +87,7 @@ fn simple() { .with_stderr("\ [UPDATING] registry `[..]`") .with_stdout("\ -hoare (0.1.1) Design by contract style assertions for Rust")); +hoare = \"^0.1.1\" # Design by contract style assertions for Rust")); } #[test] @@ -139,7 +139,7 @@ fn multiple_query_params() { .with_stderr("\ [UPDATING] registry `[..]`") .with_stdout("\ -hoare (0.1.1) Design by contract style assertions for Rust")); +hoare = \"^0.1.1\" # Design by contract style assertions for Rust")); } #[test] -- 2.30.2